<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="WCS任务Id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="id">
              <a-input v-model="model.id"  disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="WMS任务Id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskNo">
              <a-input v-model="model.relateCode"  disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="任务类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskNo">
              <a-input v-model="model.taskType"  disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="任务状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskStatus">
              <j-dict-select-tag type="list" v-model="model.taskStatus" dictCode="task_status" placeholder="请选择任务状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="RGV执行进度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskStatus">
              <j-dict-select-tag type="list" v-model="model.rgvProgress" dictCode="rgv_progress" placeholder="请选择车辆进度" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="优先级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="priority">
              <a-input-number v-model="model.priority" placeholder="请输入优先级" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="起点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="source">
              <a-input v-model="model.source" @input="validateInput(model.source)"   placeholder="请输入起点"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="终点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="target">
              <a-input v-model="model.target" @input="validateInput(model.target)" placeholder="请输入终点"  ></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="托盘号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="palletNo">
              <a-input v-model="model.palletNo" placeholder="请输入托盘号"  ></a-input>
            </a-form-model-item>
          </a-col>


          <a-col :span="24">
            <a-form-model-item label="是否分配车辆" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskType">
              <j-dict-select-tag type="list" v-model="model.assignStatus" dictCode="rgv_task_assign_status" placeholder="请选择车辆进度" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="执行车辆Id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskType">
              <a-input v-model="model.processRgvDeviceCode" placeholder="请输入任务类型" style="width: 100%" />
            </a-form-model-item>
          </a-col>

        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'WcsFourWayTaskForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/wcs/wcsFourWayTask/add",
          edit: "/wcs/wcsFourWayTask/edit",
          queryById: "/wcs/wcsFourWayTask/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      validateInput(coord) {
        const regex = /^(\([0-9]+,[0-9]+,[0-9]+\))$/; // 正则表达式，匹配格式 (x,y,z)
        if (!regex.test(coord)) {
          // 如果输入不匹配正则表达式，弹出提示窗体
          this.$message.error('坐标格式有误')
        }else {
          this.$message.success('坐标格式正确')
        }
      },
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>